﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HouseResource.Forms
{
    public partial class FileManager : Form
    {
        public FileManager()
        {
            InitializeComponent();
        }

        public FileManager(string title, string fileFullName)
        {
            this.Title = title;
            this.FileFullName = fileFullName;
            InitializeComponent();
            InitForm();
        }

        public string FileFullName { get; set; }

        public string Title { get; set; }

        private void btnSave_Click(object sender, EventArgs e)
        {
            FileStream fs = new FileStream(this.FileFullName, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.Write(txtContent.Text);
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
            FileManager.ActiveForm.Close();
        }

        private void InitForm()
        {
            FileManager.ActiveForm.Text = this.Title;
            txtContent.Text = System.IO.File.ReadAllText(this.FileFullName);
        }
    }
}